﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace 学生成绩查询及选课系统.admin
{
    public partial class studentManage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
        {
           
        }

        //static DataTable dt = new DataTable();
        //static SqlDataAdapter sda;
        //SqlCommandBuilder scb; 

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
            //string sql = "select * from student";
            //sda = new SqlDataAdapter(sql, Conndb.getconn());
            //sda.Fill(dt);
            //bind();
        }

        //public void bind()
        //{
        //    GridView1.DataSource = dt;
        //    GridView1.DataBind();
        //}




        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //using (Conndb.conn)
            //{
            //    int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
            //    SqlParameter[] pId = {new SqlParameter("@Id", id)};
            //    Conndb.getconn();
            //    string cmdString = @"DELETE FROM [student] WHERE [stuno]=@Id;";
            //    SqlDataSource2.UpdateCommand = cmdString; //关键是这里，要手动设置DeleteCommand 
            //    int result = DBAccess.GetState(cmdString,pId);
            //    //int result = dBHelper.ExecuteNonQuery(cmdString, pId);
            //    if (result > 0)
            //    {
            //        Response.Write("<script>alert('更新成功');</script>");
            //    }

            //}
            ////scb = new SqlCommandBuilder(sda);
            ////for (int i = 0; i < dt.Columns.Count; i++)
            ////{
            ////    dt.Rows[e.RowIndex][i] = e.NewValues[i].ToString();
            ////}
            ////sda.Update(dt);
            //GridView1.EditIndex = -1;
            //bind();
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btn_add_Click(object sender, EventArgs e)
        {
            //scb = new SqlCommandBuilder();
            //DataRow dr = dt.NewRow();
            //dr[0] = "666666";
            //dt.Rows.Add(dr);
            //bind();
            string name = TextBox1.Text;
            if (name == "")
            {
                SqlDataSource2.SelectCommand = "SELECT * FROM [student]";
                GridView1.DataBind();
                return;
            }
            SqlDataSource2.SelectCommand = "SELECT * FROM [student] where [stuno] ='" + name + "'";
            GridView1.DataSourceID = "SqlDataSource2";
            GridView1.DataBind();
            //GridView1.DataBind();
            //DataTable dt = DBAccess.GetTable(SqlDataSource2.SelectCommand);
            //GridView1.DataSource = dt;
            

        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName=="Insert")
            {
                GridView1.DataSourceID = null;
                GridView1.DataBind();
            }
        }

        protected void DetailsView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
        {
            GridView1.DataSourceID = "SqlDataSource2";
            GridView1.DataBind();
        }

        protected void DetailsView1_ItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            GridView1.DataSourceID = "SqlDataSource2";
            GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = TextBox1.Text;
            if (name == "")
            {
                SqlDataSource2.SelectCommand = "SELECT * FROM [student]";
                GridView1.DataBind();
                return;
            }
            SqlDataSource2.SelectCommand = "SELECT * FROM [student] where [stuno] like '%" + name + "%'";
            //GridView1.DataSourceID = null;
            //GridView1.DataBind();
            GridView1.DataSourceID = "SqlDataSource2";
            GridView1.DataBind();
        }
    }
}